home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************
- Copyright 1990 Orion Network Systems, Inc. All Rights Reserved.
-
- Name: GetUserPrefs.c
-
- Type: Procedure Implementation
-
- Function: Returns handle to user prefs or nil if none.
-
- Inputs: System Folder ref. num from an environs call
-
- Globals:
-
- Output:
-
- Side Effects:
-
-
- **************************************************************/
- #include <Memory.h>
- #include <Resources.h>
- #include <Files.h>
- #include <Types.h>
- #include <Devices.h>
- #include <Events.h>
- #include <SysEqu.h> /* FOR PORTABLE BUG */
- #include <Strings.h>
- #include <Errors.h>
- #include <Notification.h>
- #include <OSUtils.h>
-
- #include "init.h"
-
- pascal void InitMain()
- {
- short err;
- short refnum;
- StringPtr DrvrName;
- Handle dceHandle; /* FOR PORTABLE BUG */
- Handle drvrHandle; /* FOR PORTABLE BUG */
- Ptr entryPtr; /* FOR PORTABLE BUG */
- char myKeyMap[16];
- Boolean shiftHeldDown;
- short iconID = 0;
-
-
- /* Check if the shift key is down - if it is then DO NOT install: */
- GetKeys((KeyMap) myKeyMap);
- shiftHeldDown = myKeyMap[shiftKeyCode / 8] & (0x01 << (shiftKeyCode % 8));
-
- if (shiftHeldDown == false)
- {
-
- /* Install and open the driver */
-
- DrvrName = "\p.TestDrvr";
-
- err = InstallDriver(DrvrName);
-
- if (err == noErr)
- err = OpenDriver(DrvrName, &refnum);
-
- if (err == noErr)
- {
- entryPtr = *((Ptr *) UTableBase);
- entryPtr += ((~refnum) * 4);
- dceHandle = *((Handle *) entryPtr);
- drvrHandle = (Handle) ((DCtlEntry *) *dceHandle)->dCtlDriver;
- if (drvrHandle != nil) /* Just in case */
- HLock(drvrHandle);
- iconID = 128; // all went well...
-
- }
- }
- if (iconID != 0)
- ShowINIT(iconID, -1); /* Use moveX = -1 to move the default amount */
-
- return;
- }
-
- /**********************************Comment*****************************************
- * changeDRVRSlot installs the driver into the slot passed in. Because we want to keep
- * our DRVR resource ID in the resource file the same as it ever was, we GetResInfo on
- * it, and then set it back later. But, before we set it back, we set the ID of the
- * DRVR resource equal to the slot found, and then call OpenDriver. OpenDriver uses the
- * resource ID of the DRVR resource to place it in the UnitTable -- pretty easy huh?
- * The only other tricky thing is we have to Detach the resource by calling DetachResource
- * so the resource doesn't go away when the resource file gets closed (the Resource
- * Manager is our friend). The resource file gets closed when the INIT stops executing.
- **********************************End Comment************************************/
- short changeDRVRSlot(short slot, StringPtr name) /* Name is a pstring */
- {
- Handle theDRVR;
- short err, refNum;
- char DRVRname[256];
- short DRVRid;
- ResType DRVRType;
-
- if(slot != 0)
- {
- theDRVR = GetNamedResource('DRVR', name);
- if (theDRVR)
- {
- GetResInfo(theDRVR, &DRVRid, &DRVRType, &DRVRname);
- SetResInfo(theDRVR, slot, 0L);
-
- err = OpenDriver(name, &refNum);
- if(err == noErr)
- {
- /* detach the resources from the resource map */
- DetachResource(theDRVR);
-
- }
- /* Restores the previous resource attributes so they don't change
- * from startup to startup. We just want the in-memory copy to have
- * a different ID number -- not our resource in the file */
- theDRVR = GetNamedResource('DRVR', name);
- SetResInfo(theDRVR, DRVRid, nil);
- } else err = resNotFound;
- }
- return err;
- }
-
- /**********************************Comment*****************************************
- * InstallDriver installs a driver safely. Taken from iacDriver example.
- * it looks for a "slot" in the UnitTable into which the driver can be placed. If
- * it finds a "slot" it calls the procedure changeDRVRSlot to install the driver
- * into that slot.
- **********************************End Comment************************************/
-
- short InstallDriver(StringPtr drvrName)
- {
- short tsSlot;
- short err;
-
- if((tsSlot = lookForSlotInUnitTable()) != 0)
- err = changeDRVRSlot(tsSlot, drvrName);
- else err = unitTblFullErr;
-
- return err;
- }
-
- /**********************************Comment*****************************************
- * lookForSlotInUnitTable returns a short corresponding to a valid "slot" number. It'll
- range from 48 to UnitNTryCnt. If there are no slots available it returns 0. Essentially what
- we're doing here is starting at the END of the UnitTable, testing the value at each
- long-word location to see if it's nil. If it's nil, that means we can place our driver
- at that location, so we'll return the value of the "slot".
- **********************************End Comment************************************/
- short
- lookForSlotInUnitTable()
- {
- short slot;
- Ptr theBass;
- long *theVoidPtr;
- Boolean foundSlot;
-
- slot = *((short *)(UnitNtryCnt)) - 1;
- theBass = (Ptr) (*((long *) (UTableBase)));
-
- foundSlot = false;
-
- while(slot>48 && !foundSlot)
- {
- theVoidPtr = (long *)(theBass + (4L * slot));
-
- if(*theVoidPtr == 0L)
- foundSlot = true;
-
- slot -= 1;
- }
-
- slot += 1;
-
- if(!foundSlot)
- slot = 0;
-
- return slot;
- }